package com.ross.mode.store.impl;

import com.alibaba.fastjson.JSON;
import com.ross.entity.coupon.CouponResult;
import com.ross.entity.coupon.CouponService;
import com.ross.mode.store.ICommondity;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @version 1.0.0
 * @className: CouponCommodityService
 * @description: 优惠券
 * @author: zhangjunfa
 * @date: 2023/3/27 16:34
 */
@Slf4j
public class CouponCommodityService implements ICommondity {

    // 模拟注入
    private CouponService couponService = new CouponService();

    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uId, commodityId, bizId);
        log.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSON.toJSON(extMap));
        log.info("测试结果[优惠券]：{}", JSON.toJSON(couponResult));
        if (!"0000".equals(couponResult.getCode())) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
